import 'package:casdon/core/logger/log.dart';
import 'package:casdon/core/network/business_exception.dart';
import 'package:casdon/modules/login/data/repository/auth_repository.dart';
import 'package:casdon/modules/login/providers/login_provider.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class UpdatePwdUsecase {
  final AuthRepository _repository;

  const UpdatePwdUsecase(this._repository);

  Future<bool> execute({
    required String userName,
    required String newPassword,
  }) async {
    try {
      await _repository.postUpdatePwd(userName, newPassword);
      return true;
    } on BusinessException {
      rethrow;
    } catch (e) {
      Log.e("UpdatePwdUsecase 失败", e.toString(), StackTrace.current);
      return false;
    }
  }
}

final updatePwdUsecaseProvider = Provider(
  (ref) => UpdatePwdUsecase(ref.read(authRepositoryProvider)),
);
